package com.yingli.view_item.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yingli.android_studying.recycler.DynamicBean;

import com.yingli.view_item.R;

import java.util.List;

public class SampleAdapter extends RecyclerView.Adapter<SampleViewHolder>{
    private Context context;//可访问其包里的资源
    private List<DynamicBean> beans;
    public SampleAdapter(Context context, List<DynamicBean> beans) {
        this.context = context;
        this.beans = beans;

    }

    @NonNull
    @Override
    public SampleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        //xml 的样式
        View view = LayoutInflater.from(context).inflate(R.layout.activty_test,parent,false);
        return new SampleViewHolder(view);
    }

    //给每一项的viewHolder设置值（赋值）
    @Override
    public void onBindViewHolder(@NonNull SampleViewHolder holder, int position) {
        DynamicBean db = beans.get(position);
        holder.Name.setText(db.getName());
        holder.Content.setText(db.getContent());
    }
    //返回每一项视图的类型
    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    //返回列表项的数目
    @Override
    public int getItemCount() {
        return beans.size();
    }
}
